﻿@model IViewModel
@AddControls(
    new Anchor("none left")
            .SetHref(Url.Action(Str.Actions.Default, Str.Controllers.Home))
            .SetTitle("Home")
            .AddControls
            (
                new Div
                {
                    new Literal(Str.Common.ApplicationName, true)
                }.SetAttribute("style", "width:190px; height: 66px; color: #def; padding: 20px; float: left;")
            )
)
@{
    var ExistingFlags = new List<string> { "en", "de", "fr", "cs", "es", "el", "sk", "en-IE", "en-GB" };

    var action = ViewContext.RouteData.Values["action"] ?? Model.MasterModel.CurrentAction;
    var originalAction = Request.Url.AbsoluteUri;

    var holder = new PlaceHolder();

    var languages = Project.GetLanguages();
    if(languages.IsEmpty())
    {
        return;
    }

    foreach (var lang in languages
        .Where(l => l.ShowFlag)
        .Where(l => ExistingFlags.Contains(l.LanguageName)))
    {

        var actionUrl = Url.Action(Str.Business.Home.Actions.LanguageSelected
                               , Str.Controllers.Home
                               , new { id = lang.ID, originalAction });

        var imgUrl = Context.CreateUrl("/i/" + lang.LanguageName + ".png");

        holder.AddControls
        (
            new Anchor("none")
                .SetHref(actionUrl)
                .SetTitle(lang.NativeName)
                .AddControls
                (
                    !ExistingFlags.Contains(lang.LanguageName)
                        ? null
                        : new Image(imgUrl).SetAlt(lang.NativeName)
                )
        );
    }
}
@AddControls(holder)